#!/bin/sh
# 导入配置 编译依赖 脚本
source ./config.sh
# 设置环境变量
cd ..
WORK_DIR=$(pwd)
# 设置构建目录 build
BUILD_DIR=${WORK_DIR}/build
# 判断 build 文件夹是否存在
if [ ! -d ${BUILD_DIR} ]; then
    mkdir -p ${BUILD_DIR}
fi

# ndk 主目录
NDK=$BUILD_DIR/android-ndk-r21e
# 设置编译工具链
TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64
# 设置系统跟目录
SYSTEMROOT=$TOOLCHAIN/sysroot
# NDK 目录
export ANDROID_NDK=/mnt/nas/work/make/ffmpeg/android/ffmpeg/android-ndk-r21e
# 编译工具
export TOOLCHAIN_PREFIX=$NDK/toolchains/llvm/prebuilt/linux-x86_64
export PREBUIL=$NDK/toolchains/arm-linux-androideabi-4.9/prebuillinux-x86_64
export SYSTEMROOT=$NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot
# 添加编译工具目录
export PATH=$TOOLCHAIN_PREFIX/bin:$PREBUIL/bin:$PATH
OUTPUT_PATH=/make/git-work/android/opensslLib
cd /make/git-work/build/openssl
./Configure android-arm64 --prefix=$OUTPUT_PATH \
--with-zlib-include=$SYSTEMROOT/usr/include \
--with-zlib-lib=$SYSTEMROOT/usr/lib zlib no-asm no-shared no-unit-test
make clean
make -j4
make install

TARGET_HOST=aarch64-linux-android
ANDROID_ARCH=arm64-v8a
AR=$TOOLCHAIN/bin/llvm-ar
CC=$TOOLCHAIN/bin/$TARGET_HOST$MIN_SDK_VERSION-clang
AS=$CC
CXX=$TOOLCHAIN/bin/$TARGET_HOST$MIN_SDK_VERSION-clang++
LD=$TOOLCHAIN/bin/ld
RANLIB=$TOOLCHAIN/bin/llvm-ranlib
STRIP=$TOOLCHAIN/bin/llvm-strip


INSTALL_DIR=$BUILD_DIR/zlib
./configure --prefix=$INSTALL_DIR/$ANDROID_ARCH --static
#上面设置了BUILD_DIR为根目录build文件夹，所以$INSTALL_DIR/$ANDROID_ARCH的值为 build/zlib/arm64-v8a
